package com.squirrel.michale;

public class LeetCode2415 {

    public TreeNode reverseOddLevels(TreeNode root) {
        dfs(root.left, root.right, 1);
        return root;
    }

    void dfs(TreeNode left, TreeNode right, int level) {
        if (left == null) {
            return;
        }
        if (level % 2 != 0) {
            int val = right.val;
            right.val = left.val;
            left.val = val;
        }
        dfs(left.left, right.right, level + 1);
        dfs(left.right, right.left, level + 1);
    }


}
